package Demo23;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class SMISTest {
    public static void main(String[] args) {

    }
    private static Connection conn;
    public static Connection getConn() throws ClassNotFoundException, SQLException, IOException {
        //1.加载驱动程序
//        Class.forName(driver);
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        System.out.println("加载驱动成功！");
        //Class.forName("com.mysql.cj.jdbc.Driver");  mysql
        //2.创建一个连接
        String url="jdbc:sqlserver://localhost:1433;databaseName=SMIS";

//        conn=DriverManager.getConnection(url,user,pwd);

        conn= DriverManager.getConnection(url,"sa","x");
        System.out.println("连接数据库成功！");
        //conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test_demo","root","password");
        return conn;//硬编码

    }
}
